import {Component, ViewChild} from '@angular/core';
import {ControlUIWidget, SFComponent, SFCustomWidgetSchema, SFItemComponent} from '@delon/form';
import {SysParamTreeSelectComponent} from '../sys-param-tree-select/sys-param-tree-select.component';

export interface SysParamSelectSelectConfig extends SFCustomWidgetSchema {
    notShow?: string | string[];
    valueChange?: (value: string, sfItemComp: SFItemComponent, sfComp: SFComponent) => any;
}

@Component({
    selector: 'sys-param-tree-select-alain',
    templateUrl: './sys-param-tree-select-alain.component.html',
    styleUrls: ['./sys-param-tree-select-alain.component.less']
})
export class SysParamTreeSelectAlainComponent extends ControlUIWidget<SysParamSelectSelectConfig> {

    /* 用于注册小部件 KEY 值 */
    static readonly KEY = 'sys-param-tree-select-alain';

    selectedValue: any;
    emptyText = '请选择系统参数';

    @ViewChild(SysParamTreeSelectComponent, {static: true})
    treeSelectComponent: SysParamTreeSelectComponent;

    reset(_value: any): void {
        this.selectedValue = _value;
    }

    valueChange(value: string) {
        if (this.ui.valueChange) {
            this.ui.valueChange(value, this.sfItemComp, this.sfComp);
        }
    }
}
